//
//  UIFactory.swift
//  HMWeiBo
//
//  Created by Apple on 16/8/9.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit
/*
    工厂设计模式: 由父类定义协议,由子类去实现
*/
class UIFactory {
    
    // 我要一个button
    class func getButton(title: String,textColor: UIColor?,image: String?,bgImage: String?,target: AnyObject,action:Selector) -> UIButton{
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setTitle(title, forState: UIControlState.Normal)
        if let image = image{
            
            button.setImage(UIImage(named: image), forState: UIControlState.Normal)
            
        }
        // targe千万不要填写self
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        if let textColor = textColor {
            
            button.setTitleColor(textColor, forState: UIControlState.Normal)
        }
        
        if let bgImage = bgImage {
            
            button.setBackgroundImage(UIImage(named: bgImage), forState: UIControlState.Normal)
        }
        
        button.backgroundColor = UIColor.darkGrayColor()
        
        return button
    }
    
}
